package model;

// Generated 25-Nov-2013 20:54:41 by Hibernate Tools 4.0.0

import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;

import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 * User generated by hbm2java
 */
@Entity
@Table(name = "user")
public class User implements java.io.Serializable {

	private static final long serialVersionUID = 4810088873589185708L;
	private Integer userId;
	private String username;
	private byte[] password;
	private PaymentMethod paymentMethod;
	private String fullname;
	private String email;
	private boolean gender;
	private Date datecreated;
	private byte[] salt;
	private Set<UserOrder> userOrders = new HashSet<UserOrder>(0);
	private Set<UserAddressHistory> userAddressHistories = new HashSet<UserAddressHistory>(
			0);
	private Set<RoleMember> userRoleMembers = new HashSet<RoleMember>(0);
	private String phoneNumber;
	private Integer score;
	public User() {
	}

	public User(String username, byte[] password, PaymentMethod paymentMethod,
			String fullname, String email, boolean gender, Date datecreated,
			byte[] salt, Set<UserOrder> userOrders,
			Set<UserAddressHistory> userAddressHistories,
			Set<RoleMember> userRoleMembers, String phoneNumber) {
		super();
		this.username = username;
		this.password = password;
		this.paymentMethod = paymentMethod;
		this.fullname = fullname;
		this.email = email;
		this.gender = gender;
		this.datecreated = datecreated;
		this.salt = salt;
		this.userOrders = userOrders;
		this.userAddressHistories = userAddressHistories;
		this.userRoleMembers = userRoleMembers;
		this.phoneNumber = phoneNumber;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "user_id", unique = true, nullable = false)
	public Integer getUserId() {
		return this.userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	@ManyToOne
	@LazyCollection(LazyCollectionOption.FALSE)
	@JoinColumn(name = "payment_method_id")
	public PaymentMethod getPaymentMethod() {
		return this.paymentMethod;
	}

	public void setPaymentMethod(PaymentMethod paymentMethod) {
		this.paymentMethod = paymentMethod;
	}

	@Column(name = "fullname")
	public String getFullname() {
		return fullname;
	}

	public void setFullname(String fullname) {
		this.fullname = fullname;
	}

	@Column(name = "email", nullable = false)
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "gender", nullable = false)
	public boolean getGender() {
		return this.gender;
	}

	public void setGender(boolean gender) {
		this.gender = gender;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "datecreated", nullable = false, length = 19)
	public Date getDatecreated() {
		return this.datecreated;
	}

	public void setDatecreated(Date datecreated) {
		this.datecreated = datecreated;
	}

	@OneToMany(mappedBy = "user")
	@LazyCollection(LazyCollectionOption.FALSE)
	public Set<UserOrder> getUserOrders() {
		return this.userOrders;
	}

	public void setUserOrders(Set<UserOrder> userOrders) {
		this.userOrders = userOrders;
	}

	@OneToMany(mappedBy = "user")
	@LazyCollection(LazyCollectionOption.FALSE)
	public Set<UserAddressHistory> getUserAddressHistories() {
		return this.userAddressHistories;
	}

	public void setUserAddressHistories(
			Set<UserAddressHistory> userAddressHistories) {
		this.userAddressHistories = userAddressHistories;
	}

	@Column(name = "username")
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name = "password")
	public byte[] getPassword() {
		return password;
	}

	public void setPassword(byte[] password) {
		this.password = password;
	}

	@Column(name = "salt")
	public byte[] getSalt() {
		return salt;
	}

	public void setSalt(byte[] salt) {
		this.salt = salt;
	}

	@OneToMany(mappedBy = "user")
	@LazyCollection(LazyCollectionOption.FALSE)
	public Set<RoleMember> getUserRoleMembers() {
		return userRoleMembers;
	}

	public void setUserRoleMembers(Set<RoleMember> userRoleMembers) {
		this.userRoleMembers = userRoleMembers;
	}

	@Column(name="phone_number")
	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((datecreated == null) ? 0 : datecreated.hashCode());
		result = prime * result + ((email == null) ? 0 : email.hashCode());
		result = prime * result
				+ ((fullname == null) ? 0 : fullname.hashCode());
		result = prime * result + (gender ? 1231 : 1237);
		result = prime * result + Arrays.hashCode(password);
		result = prime * result + Arrays.hashCode(salt);
		result = prime * result + ((userId == null) ? 0 : userId.hashCode());
		result = prime * result
				+ ((username == null) ? 0 : username.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (datecreated == null) {
			if (other.datecreated != null)
				return false;
		} else if (!datecreated.equals(other.datecreated))
			return false;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		if (fullname == null) {
			if (other.fullname != null)
				return false;
		} else if (!fullname.equals(other.fullname))
			return false;
		if (gender != other.gender)
			return false;
		if (!Arrays.equals(password, other.password))
			return false;
		if (!Arrays.equals(salt, other.salt))
			return false;
		if (userId == null) {
			if (other.userId != null)
				return false;
		} else if (!userId.equals(other.userId))
			return false;
		if (username == null) {
			if (other.username != null)
				return false;
		} else if (!username.equals(other.username))
			return false;
		return true;
	}

	@Column(name="score")
	public Integer getScore() {
		return score;
	}

	public void setScore(Integer score) {
		this.score = score;
	}

	
}
